package com.example.day23.ex02;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

public class ComparatorDemo {
    public static void main(String[] args) {
        ArrayList<String> array = new ArrayList<>();
        array.add("张三");
        array.add("李");
        array.add("王五");
        array.add("赵六");
        System.out.println("排序前"+array);
        Collections.sort(array,  getComparator());
        System.out.println("排序后"+array);
    }
    private static Comparator<String>getComparator(){
        return (s1,s2)->s1.length()-s2.length();
    }
}
